package com.aigou.admin.service.impl;

import com.aigou.admin.dao.CarouselFigureDao;
import com.aigou.admin.dao.UserDao;
import com.aigou.admin.dao.impl.CarouselFigureDaoImpl;
import com.aigou.admin.dao.impl.UserDaoImpl;
import com.aigou.admin.entity.CarouselFigure;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.User;
import com.aigou.admin.service.CarouselFigureService;
import com.aigou.admin.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Hor
 * @Date: 2024/11/29 09:30
 * @Version: 1.0
 */

@Service
@AllArgsConstructor
public class CarouselFigureServiceImpl implements CarouselFigureService {

    private final CarouselFigureDao carouselFigureDao;

    @Override
    public List<CarouselFigure> findAll() {
        return carouselFigureDao.selectAll();
    }

    @Override
    public CarouselFigure findById(String id) {
        return carouselFigureDao.selectById(id);
    }

    @Override
    public Boolean save(CarouselFigure carouselFigure) {
        return carouselFigureDao.insert(carouselFigure);
    }

    @Override
    public Boolean update(CarouselFigure carouselFigure) {
        return carouselFigureDao.update(carouselFigure);
    }

    @Override
    public Boolean remove(String id) {
        return carouselFigureDao.delete(id);
    }

    @Override
    public PageEntity<CarouselFigure> findCarouselFiguresByPage(Integer currentPage, Integer pageSize) {
        Integer total = carouselFigureDao.selectCount();
        List<CarouselFigure> carouselFigures = carouselFigureDao.selectUserByLimit((currentPage - 1) * pageSize, pageSize);
        PageEntity<CarouselFigure> pageEntity = new PageEntity<>();
        pageEntity.setTotal(total);
        pageEntity.setPageSize(pageSize);
        pageEntity.setCurrent(currentPage);
        pageEntity.setRecords(carouselFigures);
        return pageEntity;
    }
}
